home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-19 | 3.1 KB | 176 lines | [TEXT/CWIE] |
- //
- // You may incorporate this sample code into your
- // applications without restriction. This sample code has
- // been provided "AS IS" and the responsibility for its
- // operation is 100% yours. You are not permitted to
- // redistribute the source as "Apple sample code" after
- // having made changes. If you're going to re-distribute
- // the source, we require that you make it clear in the
- // source that the code was descended from Apple sample
- // code, but that you've made changes.
- //
-
- #define OLDROUTINELOCATIONS 0
- #define OLDROUTINENAMES 0
- #define SystemSevenOrLater 1
-
- #ifndef __FONTS__
- # include <Fonts.h>
- #endif
-
- #ifndef __ERRORS__
- # include <Errors.h>
- #endif
-
- #ifndef __RESOURCES__
- # include <Resources.h>
- #endif
-
- #include "MoveableModalDialog.h"
-
- enum
- {
- kDialogItem_Button_None,
- kDialogItem_Button_Quit,
- kDialogItem_Button_RGB,
- kDialogItem_Button_Resource,
- kDialogItem_Button_NIL
- };
-
- static pascal OSErr InitMac (void)
- {
- MaxApplZone ( );
- InitGraf (&(qd.thePort));
- InitFonts ( );
- InitWindows ( );
- InitMenus ( );
- TEInit ( );
- InitDialogs (nil);
-
- return noErr;
- }
-
- static pascal OSErr myMakeRGBPat
- (const RGBColor *color, Boolean inSysHeap, PixPatHandle *pphp)
- {
- OSErr err = noErr;
-
- THz savedZone;
-
- if (inSysHeap)
- {
- savedZone = GetZone ( );
- SetZone (SystemZone ( ));
- }
-
- if (!(*pphp = NewPixPat ( )))
- err = QDError ( );
- else
- {
- MakeRGBPat (*pphp,color);
- err = QDError ( );
- if (err)
- {
- DisposePixPat (*pphp);
- *pphp = nil;
- }
- }
-
- if (inSysHeap)
- SetZone (savedZone);
-
- return err;
- }
-
- static pascal OSErr myGetPixPat (short resID, Boolean inSysHeap, PixPatHandle *pphp)
- {
- OSErr err = noErr;
-
- Handle pixPatResH = Get1Resource ('ppat',resID);
- if (!(err = ResError ( )))
- {
- if (!pixPatResH)
- err = resNotFound;
- else
- {
- THz savedZone;
-
- if (inSysHeap)
- {
- savedZone = GetZone ( );
- SetZone (SystemZone ( ));
- }
-
- *pphp = GetPixPat (resID);
- if (!*pphp) err = QDError ( );
-
- if (inSysHeap)
- SetZone (savedZone);
-
- ReleaseResource (pixPatResH);
- if (!err) err = ResError ( );
- }
- }
-
- return err;
- }
-
- static pascal OSErr SetDeskCPatFromRGB (void)
- {
- PixPatHandle pph = nil;
- RGBColor rgbGray = { 0x7FFF, 0x7FFF, 0x7FFF };
- OSErr err = myMakeRGBPat (&rgbGray,true,&pph);
- if (!err) SetDeskCPat (pph);
- return err;
- }
-
- static pascal OSErr SetDeskCPatFromResource (void)
- {
- PixPatHandle pph = nil;
- OSErr err = myGetPixPat (128,true,&pph);
- if (!err) SetDeskCPat (pph);
- return err;
- }
-
- void main (void)
- {
- if (InitMac ( ))
- SysBeep (10);
- else
- {
- DialogRef dlgRef = GetNewDialog (128,nil,(WindowRef)-1);
- if (dlgRef)
- {
- short itemHit;
-
- SetDialogDefaultItem (dlgRef,kDialogItem_Button_Quit);
-
- do
- {
- MoveableModalDialog (StdFilterProc,&itemHit);
-
- switch (itemHit)
- {
- case kDialogItem_Button_RGB :
-
- (void) SetDeskCPatFromRGB ( );
- break;
-
- case kDialogItem_Button_Resource :
-
- (void) SetDeskCPatFromResource ( );
- break;
-
- case kDialogItem_Button_NIL :
-
- SetDeskCPat (nil);
- break;
- }
- }
- while (itemHit != kDialogItem_Button_Quit);
-
- DisposeDialog (dlgRef);
- }
- }
- }
-